using System.Collections.Generic;

namespace Quiki.ExpressionParsers
{
    public class TemplateExpressionParser : BinaryWikiTokenInlineExpressionParser
    {
        public TemplateExpressionParser() : base ("{{", "}}", ElementConstructor)
        {
        }

        private static WikiTextElement ElementConstructor (string text)
        {
            WikiTemplateElement templateElement = new WikiTemplateElement();

            string[] splits = text.Split('|');

            templateElement.TemplateName = splits[0].Trim();

            List<string> parameters = new List<string>();
            for (int i = 1; i < splits.Length; i++)
                parameters.Add(splits[i].Trim());

            templateElement.TemplateParameters = parameters;

            return templateElement;
        }
    }
}